<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var LongestSubstring = function (s) {
        // console.log(s)
        // 新变量用来接收 遍历的字符串
        let str = ''
        // 字符串长度
        let len = 0
        for (const i of s) {
          if (str.indexOf(i) === -1) {
            str += i
          } else {
            len = str.length > len ? str.length : len
            str = i
          }
        }
        return len
      }

      // LongestSubstring('abcabcbb')
      console.log(LongestSubstring('pwwkew'))
      console.log(LongestSubstring('abcabcbb'))
    </script>
  </body>
</html>
